<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use app\common\ApiResponse;
use app\service\AccountCategoryService;
use think\Request;

class AccountCategoryController extends BaseController
{
    private $accountCategoryService;

    public function __construct()
    {
        $app = app(); // 获取当前应用的实例
        $this->accountCategoryService = new AccountCategoryService($app);
    }
    /**
     * 查询分类列表
     *
     * @return \think\Response
     */
    public function getList()
    {
        $data = input();
        /*if(empty($data['cate_id'])){
            return json("缺少参数cate_id");
        }*/
        $list = $this->accountCategoryService->getList($data);
        return ApiResponse::successList($list, "查询成功");
    }

    /**
     * 添加分类
     *
     * @return \think\Response
     */
    public function create()
    {
        $data = input();
        if(empty($data['cate_name'] ) || empty($data['account_type'])){
            return json("缺少参数cate_name|account_type");
        }
        $res = $this->accountCategoryService->create($data);
        return ApiResponse::success($res, "添加成功");
    }

    /**
     * 修改分类
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function update()
    {
        $data = input();
        if(empty($data['cate_id'] ) || empty($data['cate_name'] ) || empty($data['account_type'])){
            return json("缺少参数cate_id|cate_name|account_type");
        }
        $res = $this->accountCategoryService->update($data);
        return ApiResponse::success($res, "修改成功");
    }

    /**
     * 查询分类
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function getOne()
    {
        $data = input();
        if(empty($data['cate_id'] )){
            return json("缺少参数cate_id");
        }
        $res = $this->accountCategoryService->getOne($data);
        return ApiResponse::success($res, "查询成功");
    }

    /**
     * 删除分类
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete()
    {
        $data = input();
        if(empty($data['cate_id'] )){
            return json("缺少参数cate_id");
        }
        $res = $this->accountCategoryService->delete($data);
        return ApiResponse::success($res, "删除成功");
    }
}
